package com.em.mission;

import android.content.Context;

/**
 * Created by admin on 16/7/30.
 */

public abstract class MissionItem extends Mission {

    public int retryTime;
    public Context mContext;

    protected  MissionItem(){
        isExecute = false;
        maxRetryTime = DEFAULT_RETRY_TIME;
    };

    protected MissionItem(Context mContext,String name){
        this(name);
        this.mContext = mContext;
    }


    public  MissionItem(String name){
        this();
        this.missionName = name;
    }

    protected MissionItem(String missionName , String tag){
        this.missionName = missionName;
        this.tag  = tag;
    }

    private void beforeItemExecute(MissionListener listener){
        beforeExecute();
        if (listener!=null){
            listener.beforeExecuteListener(this);
        }
    };

    private void onItemExecute(MissionListener listener,MissionResultListener resultListener){
        onExecute(resultListener);
        if (listener!=null){
            listener.onExecute(this);
        }
    };

    private void afterItemExecute(MissionListener listener){
        afterExecute();
        if (listener!=null){
            listener.afterExecute(this);
        }
    };

    @Override
    protected void start(MissionListener listener,MissionResultListener resultListener){
        beforeItemExecute(listener);
        onItemExecute(listener,resultListener);
        afterItemExecute(listener);
    };
    

}
